package com.pqy.ts.controller;


import com.pqy.ts.entity.TUser;
import com.pqy.ts.entity.vo.R;
import com.pqy.ts.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author panqiyi
 * @since 2022-06-10
 */
@RestController
@RequestMapping("/ts/tuser")
@CrossOrigin
public class TUserController {

    @Autowired
    private TUserService userService;

    // 用户登录后，存储登录信息到session, 获取用户登录信息
    @GetMapping("getLoginUser")
    public R getLoginUser(HttpSession session){
        // 模拟登录数据
        //TUser tUser = new TUser();
//        tUser.setId("11232");
//        tUser.setAvatar("https://s1.ax1x.com/2022/06/10/Xc9J2Q.png");
//        tUser.setUsername("周杰伦");

        //tUser.setId("66445");
        //tUser.setAvatar("https://s1.ax1x.com/2022/06/10/Xc9wV0.png");
        //tUser.setUsername("刘德华");
        TUser tUser = userService.getById("66445");
        session.setAttribute("user",tUser);

        TUser user = (TUser) session.getAttribute("user");
       // System.out.println("----;;"+user);
        if (user==null){
            return R.error().message("未登录，请先登录！");
        }else {
            return R.ok().data("user",user);
        }
    }
}

